<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Refresh All : DataMapper ORM - User Guide</title>

<link rel="shortcut icon" type="image/png" href="../images/favicon.png" />
<link rel="stylesheet" type="text/css" media="all" href="../css/userguide.css" />
<link rel="alternate" type="application/rss+xml" title="Datamapper ORM Updates Feed" href="/rss.xml" />

<meta http-equiv="expires" content="-1" />
<meta http-equiv= 'pragma' content="no-cache" />
<meta name="robots" content="all" />

</head>

<body>

<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"></div></div>
<div id="nav2"><a name="top">&nbsp;</a><a id="nav_toggle" href="#"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>DataMapper ORM</h1></td>
<td id="breadcrumb_right"><a href="toc.html">Table of Contents Page</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->

<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="/">Datamapper ORM Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
Refresh All
</td>
</tr>

</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">


<h1>Refresh All</h1>

<p>Refresh All is really only used in one scenario. For example, if you get a number of object, loop through its all list, and delete one or more records, but not all of them.  Refresh All will do just that, refresh the all list so the deleted items are removed.  We're not able to dynamically remove them from the all list while you're looping through it as that would cause issues with the loop itself. Here's an example of when you'd use refresh_all():</p>

<pre>
<samp>// Get a number of books from the year 2000
</samp><var>$b </var><kbd>= new </kbd><var>Book</var><kbd>();
</kbd><var>$b</var><kbd>-&gt;</kbd><var><u>where</u></var><kbd>(</kbd><dfn>'year'</dfn><kbd>, </kbd><var>2000</var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();

</kbd><samp>// Loop through the all list and delete those that are fiction
</samp><kbd>foreach (</kbd><var>$b</var> <kbd>as </kbd><var>$book</var><kbd>)
{
    if (</kbd><var>$book</var><kbd>-&gt;</kbd><var>fiction</var><kbd>)
    {
        </kbd><var>$book</var><kbd>-&gt;</kbd><var><u>delete</u></var><kbd>();
    }
}

</kbd><samp>// Refresh the book objects all list to remove the deleted entries (which are simply empty entries in the all list now)
</samp><var>$b</var><kbd>-&gt;</kbd><var><u>refresh_all</u></var><kbd>();

</kbd><samp>// Now we can loop through the all list again looking at only existing objects
</samp><kbd>foreach (</kbd><var>$b</var> <kbd>as </kbd><var>$book</var><kbd>)
{
    echo </kbd><var>$book</var><kbd>-&gt;</kbd><var>name </var><kbd>.</kbd><dfn>"&lt;br /&gt;"</dfn><kbd>;
}</kbd>
</pre>

<p>Alternatively, you could instead run your get query again but that will execute a database call whereas Refresh All just removes empty records from the objects all list.</p>

</div>
<!-- END CONTENT -->


<div id="footer">
<p>
<span id="footer_previous">Previous Topic:&nbsp;&nbsp;<a href=""></a>
&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;</span>
<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="../index.html">User Guide Home</a>
<span id="footer_next">&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
Next Topic:&nbsp;&nbsp;<a href=""></a></span>
</p>
<div id="copyrights">
<p><a href="/">Datamapper ORM</a> &nbsp;&middot;&nbsp; Copyright &copy; 2010-2011 &nbsp;&middot;&nbsp; Harro "WanWizard" Verton</p>
<p><a href="license.html">Other License Information</a></p>
</div>
</div>

<script type="text/javascript" src="../js/mootools.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<script type="text/javascript">
<!--
	window.addEvent('domready', function() {

		// Create Menu
		var menu = new Menu({
			basepath: '../',
			pagespath: ''
		});

	});
//-->
</script>
</body>
</html>
